
#ifndef __3DLIGHT_H__
#define __3DLIGHT_H__

#include <vector>

#include "ObjInst.h"

#include "3dRenderDef.h"
#include "Vector.h"
#include "Obj4d.h"
#include "RenderList.h"

#include "DxDrawEnv.h"

// defines for light types
#define LIGHTV1_ATTR_AMBIENT      0x0001    // basic ambient light
#define LIGHTV1_ATTR_INFINITE     0x0002    // infinite light source
#define LIGHTV1_ATTR_DIRECTIONAL  0x0002    // infinite light source (alias)
#define LIGHTV1_ATTR_POINT        0x0004    // point light source
#define LIGHTV1_ATTR_SPOTLIGHT1   0x0008    // spotlight type 1 (simple)
#define LIGHTV1_ATTR_SPOTLIGHT2   0x0010    // spotlight type 2 (complex)

#define LIGHTV1_STATE_ON          1         // light on
#define LIGHTV1_STATE_OFF         0         // light off


class C3dLight
{
public:

	C3dLight()
	:	state(0), id(0), attr(0),
		kc(0), kl(0), kq(0), spot_inner(0), spot_outer(0), pf(0),
		iaux1(0), iaux2(0), faux1(0), faux2(0), ptr(NULL)
	{
		memset(&c_ambient, 0, sizeof(c_ambient));		// ambient light intensity
		memset(&c_diffuse, 0, sizeof(c_diffuse));		// diffuse light intensity
		memset(&c_specular, 0, sizeof(c_specular));		// specular light intensity
	}

	virtual ~C3dLight()
	{

	}

	int go()
	{
		return 0;
	}

	int Init(	int			_id,
				int         _state,      // state of light
				int         _attr,       // type of light, and extra qualifiers
				RGBAV1      _c_ambient,  // ambient light intensity
				RGBAV1		_c_diffuse,  // diffuse light intensity
				RGBAV1      _c_specular, // specular light intensity
				CPoint4d&	_pos,        // position of light
				CVector4d&	_dir,        // direction of light
				float       _kc,         // attenuation factors
				float       _kl, 
				float       _kq,  
				float       _spot_inner, // inner angle for spot light
				float       _spot_outer, // outer angle for spot light
				float       _pf);        // power factor/falloff for spot lights

	int Reset();


	//member
	int		state; // state of light
	int		id;    // id of light
	int		attr;  // type of light, and extra qualifiers

	RGBAV1	c_ambient;   // ambient light intensity
	RGBAV1	c_diffuse;   // diffuse light intensity
	RGBAV1	c_specular;  // specular light intensity

	CPoint4d	pos;			// position of light
	CVector4d	dir;			// direction of light
	float		kc, kl, kq;		// attenuation factors
	float		spot_inner;		// inner angle for spot light
	float		spot_outer;		// outer angle for spot light
	float		pf;				// power factor/falloff for spot lights

	int			iaux1, iaux2;	// auxiliary vars for future expansion
	float		faux1, faux2;
	void		*ptr;

protected:

};


class C3dLightMgr
{
public:

	typedef std::vector<C3dLight*>		LightVct;

	C3dLightMgr()
	{
		m_lights = NULL;
		m_lightCount = 0;
	}

	~C3dLightMgr()
	{

	}

	int Init(PDxDrawEnv pDxDrawEnv, int lightCount = 8)
	{
		m_pDxDrawEnv	= pDxDrawEnv;
		m_lightCount	= lightCount;

		m_lights = new C3dLight[m_lightCount];

		return 0;
	}

	int Reset()
	{
		//
		for (int i=0; i<m_lightCount; i++)
			m_lights[i].Reset();

		delete[] m_lights;

		m_lights = NULL;

		return 0;
	}

	C3dLight* operator[] (int nIndex)
	{
		return &m_lights[nIndex];
	}

	int Light_Obj4d_World16(CObj4d& obj,			// object to process
							int max_lights);		// maximum lights in list

	int Light_RenderList_World16(CRenderList& rend_list,		// object to process
								int max_lights);					// maximum lights in list

protected:

	PDxDrawEnv			m_pDxDrawEnv;
	int					m_lightCount;

	C3dLight*			m_lights;
};

typedef CObjInst< C3dLightMgr > LightMgrInst;

#endif